<?php

require __DIR__ . '/../vendor/autoload.php';

use Web3\Providers\HttpProvider;
use Web3\RequestManagers\HttpRequestManager;
use Web3\Web3;

$url = 'https://ropsten.infura.io/v3/8f762549c8c341388ac03552835a0358';
$web3 = new Web3(new HttpProvider(new HttpRequestManager($url, 5)));

$address = '0x9Ba6EC8fA4CD0AC4b805c605cEBE4901046c4041';

$res = $web3->getEth()->getBalance($address, function ($err, $wei) use ($web3) {
    if ($err !== null) {
        echo 'Error: ' . $err->getMessage();
        return;
    }
    [$bnq, $bnr] = $web3->getUtils()->fromWei($wei->toString(), 'ether');
    $arr = [$bnq->toString(), $bnr->toString()];
    $balance = implode('.', $arr);
    var_dump('banance: ' . $balance);
});
